//
//  ViewController.m
//  Runtimer
//
//  Created by ZhangSai on 2021/8/27.
//

#import "ViewController.h"
#include <objc/runtime.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    dispatch_group_t group = dispatch_group_create();

        // 1. 调度组
    /*
        dispatch_group_t group = dispatch_group_create();

        // 2. 队列
        dispatch_queue_t q = dispatch_get_global_queue(0, 0);

        // 3. 将任务添加到队列和调度组
        dispatch_group_async(group, q, ^{
            [NSThread sleepForTimeInterval:1.0];
            NSLog(@"任务 1 %@", [NSThread currentThread]);
        });
        dispatch_group_async(group, q, ^{
            NSLog(@"任务 2 %@", [NSThread currentThread]);
        });
        dispatch_group_async(group, q, ^{
            NSLog(@"任务 3 %@", [NSThread currentThread]);
        });

        // 4. 监听所有任务完成
        dispatch_group_notify(group, q, ^{
            NSLog(@"OVER %@", [NSThread currentThread]);
        });

        // 5. 判断异步
        NSLog(@"come here");
*/
//    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

    /*

        // 全局队列
        NSOperationQueue *q = [[NSOperationQueue alloc] init];

        for (int i = 0; i < 10; ++i) {
            [q addOperationWithBlock:^{
                NSLog(@"%@ %d", [NSThread currentThread], i);
            }];
        }

        NSBlockOperation *op1 = [NSBlockOperation blockOperationWithBlock:^{
            NSLog(@"block %@", [NSThread currentThread]);
        }];
        [q addOperation:op1];

        NSInvocationOperation *op2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(downloadImage) object:@"invocation"];
        [q addOperation:op2];

*/
    [self runtimer];
    
}

- (void)downloadImage {
    
}

- (void)runtimer {
    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    but.frame = CGRectMake(100, 150, 50, 50);
    [but setTitle:@"点我" forState:UIControlStateNormal];
    but.backgroundColor = [UIColor redColor];
    [but addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:but];
}

void dynamicMethodIMP(id self, SEL _cmd) {
    NSLog(@" >> dynamicMethodIMP");
}


+ (BOOL)resolveInstanceMethod:(SEL)name {
    
    if (name == @selector(MissMethod)) {
           class_addMethod([self class], name, (IMP)dynamicMethodIMP, "v@:");
           return YES;
       }
         
       return [super resolveInstanceMethod:name];
}

//- (id)forwardingTargetForSelector:(SEL)aSelector {
//    return [UIButton new];
//}

@end
